﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Admin
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Main.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-08-26   Created by 杨光远 V1.00.0000
    /// 功能说明：用户管理
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Main : Component.PageBase
    {
        #region---基本变量实例化---
        Vehicle.BLLShow.AdminShow admin = new Vehicle.BLLShow.AdminShow();
        //     Vehicle.BLL.Admin b_Admin = new Vehicle.BLL.Admin();                       *****原来使用方法
        //     Vehicle.BLL.Log b_Log = new Vehicle.BLL.Log();                             *****原来使用方法
        Vehicle.Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbtn_AllDelete.Attributes.Add("onClick", "return confirm('是否要删除这些记录');");
                admin.Admin_DropDownListBind1(Drop_Select);
                //b_Admin.DropDownListBind1(Drop_Select);//绑定角色                        *****原来使用方法
                RepeaterDataBind();//绑定数据
            }
        }
        /// <summary>
        /// 绑定页面Repeater数据
        /// </summary>
        public void RepeaterDataBind()
        {
            //如果选择为全部则选择值为0 通用实体层匹配条件为1 结果为1  Drop_Select.SelectedValue == "0" ? "1": Drop_Select.SelectedValue
           
           // this.Anp_Page.RecordCount = b_Admin.GetAllSearchCount(new Vehicle.Model.ComponentsInfo("Admin", Drop_Select.SelectedValue == "0" ? "1" : "R_ID", Drop_Select.SelectedValue == "0" ? "1" : Drop_Select.SelectedValue,"A_IsDelete","0", "A_ID"));//根据下拉菜单选择的进行数据绑定获得总数
            m_ComponentsInfo.startIndex = Anp_Page.StartRecordIndex;//当前页的起始索引数
            m_ComponentsInfo.endIndex = Anp_Page.EndRecordIndex;//当前页的结束索引数
            m_ComponentsInfo.condition = Drop_Select.SelectedValue == "0" ? "1" : "R_ID";//条件名称一
            m_ComponentsInfo.result = Drop_Select.SelectedValue == "0" ? "1" : Drop_Select.SelectedValue;//匹配条件结果一
            m_ComponentsInfo.Tcondition = "A_IsDelete";//条件名称二
            m_ComponentsInfo.Tresult = "0";//匹配条件结果二
            admin.Admin_RepeaterBind(ReptShow, m_ComponentsInfo);//绑定Repeater控件
         //   b_Admin.RepeaterBind(ReptShow, m_ComponentsInfo);//绑定Repeater控件           *****原来使用方法
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }
            
        }
        /// <summary>
        /// 根据角色选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Drop_Select_SelectedIndexChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        /// <summary>
        /// ReptShow激发事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                admin.AllUpdate(new Vehicle.Model.ComponentsInfo("Admin", "A_IsDelete", "1", "A_ID", e.CommandArgument.ToString()));//假删除用户信息
               // b_Admin.AllUpdate(new Vehicle.Model.ComponentsInfo("Admin", "A_IsDelete", "1", "A_ID", e.CommandArgument.ToString()));//假删除用户信息
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
        }
        /// <summary>
        /// ReptShow绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((LinkButton)(e.Item.FindControl("Lbtn_Delete"))).Attributes.Add("onClick", "return   confirm('您确定删除该用户？');");
                Label lab_R_ID = (Label)e.Item.FindControl("lab_R_ID");
                try
                {
                    lab_R_ID.Text = admin.GetModel(new Vehicle.Model.ComponentsInfo("Role", "R_ID", lab_R_ID.Text, "R_ID")).Rows[0]["R_Name"].ToString();//绑定用户角色名
                    // lab_R_ID.Text = b_Admin.GetModel(new Vehicle.Model.ComponentsInfo("Role", "R_ID", lab_R_ID.Text, "R_ID")).Rows[0]["R_Name"].ToString();//绑定用户角色名                       *****原来使用方法
                }
                catch 
                {
                    lab_R_ID.Text = "无";
                }
            }
        }
        /// <summary>
        /// 全部删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtn_AllDelete_Click(object sender, EventArgs e)
        {
            int Count = 1;//定义计数器
            foreach (RepeaterItem item in ReptShow.Items)
            {
              CheckBox chk = (CheckBox)item.FindControl("Chk_Num");
              if (chk.Checked)
              {
                  Count++;
                  // b_Admin.AllUpdate(new Vehicle.Model.ComponentsInfo("Admin", "A_IsDelete", "1", "A_ID", chk.ToolTip));//假删除用户信息                       *****原来使用方法
                  // b_log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功删除编号为" + chk.ToolTip + "的用户信息"));//添加日志                    *****原来使用方法
                  admin.AllUpdate(new Vehicle.Model.ComponentsInfo("Admin", "A_IsDelete", "1", "A_ID", chk.ToolTip));//假删除用户信息
                  admin.Log_Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功删除编号为" + chk.ToolTip + "的用户信息"));//添加日志
              }
            }
            if (Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('您还没有进行选择！')", true);
            }
        }
        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        #endregion
    }
}
